import 'package:flutter/material.dart';
import 'package:gzmall_app/common/color_common.dart';

class EmptyWidget extends StatefulWidget {
  String tips;
  String btnText;
  Function reloadAction;
  EmptyWidget({this.tips, this.btnText, this.reloadAction});

  _EmptyWidgetState createState() => _EmptyWidgetState();
}

class _EmptyWidgetState extends State<EmptyWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      color: Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Padding(
            padding: const EdgeInsets.only(bottom: 10.0),
            child: Text(
              widget?.tips ?? "暂无数据",
              style: TextStyle(fontSize: 18.0),
            ),
          ),
          widget.reloadAction != null
              ? InkWell(
                  onTap: () {
                    widget.reloadAction();
                  },
                  child: _getTagView(widget?.btnText ?? "重新加载", Colors.white,
                      ColorCommon.primaryColor, ColorCommon.primaryColor),
                )
              : Container(),
        ],
      ),
    );
  }

  Widget _getTagView(
      String text, Color bgColor, Color borderColor, Color textColor,
      {DecorationImage image}) {
    BoxDecoration decoration;
    if (image == null) {
      decoration = BoxDecoration(
          color: bgColor,
          border: Border.all(color: borderColor),
          borderRadius: BorderRadius.all(Radius.circular(100.0)));
    } else {
      decoration = BoxDecoration(image: image);
    }
    return Container(
      padding: const EdgeInsets.only(left: 8.0, right: 8.0),
      decoration: decoration,
      child: Text(
        text,
        style: TextStyle(fontSize: 16.0, color: textColor),
      ),
    );
  }
}
